import { request, qs } from "../service";

const right = {

  /**
   * 查找权限列表
   */
  findRightList(param) {
    return request({
      url: '/auth/right/findByAttributes',
      method: 'get',
      params: addDefaultParam(param)
    })
  },

  /**
   * 查找权限总数
   */
  findRightListMax(param) {
    return request({
      url: '/auth/right/findMaxByAttributes',
      method: 'get',
      params: addDefaultParam(param)
    })
  },

  /**
   * 添加权限
   */
  addRight(param) {
    return request({
      url: '/auth/right/add',
      method: 'post',
      data: addDefaultParam(param)
    });
  },

  /**
   * 更新权限
   */
  updateRight(param) {
    return request({
      url: '/auth/right/update',
      method: 'put',
      data: addDefaultParam(param)
    });
  },

  /**
   * 删除权限
   */
  delRight(rightId) {
    return request({
      url: '/auth/right/delete/' + rightId,
      method: 'delete'
    });
  },

  /**
   * 批量删除菜单
   */
   delBatchRight(param) {
    return request({
      url: `/auth/right/deleteBatch`,
      method: 'delete',
      params: param,
      paramsSerializer: params => {
        return qs.stringify(params, {
          indices: false
        })
      }
    })
  }

}

/**
 * 添加缺省参数值
 * @param {*} param 原始参数
 * @returns 携带缺省参数返回
 */
 function addDefaultParam(param) {
  let params = param;
  params['app'] = process.env.VUE_APP_SYSTEM_NAME;
  return params;
}

export default right;
